import { getSessionInfo, setSessionInfo } from '@/utils/storage'
import variables from '@/styles/variables.module.scss'
import { MAIN_COLOR, DEFAULT_COLOR } from '@/constants'

const state = {
  mainColor: getSessionInfo(MAIN_COLOR) || DEFAULT_COLOR,
  variables
}

const mutations = {
  /**
   * 设置主题色
   */
  SET_MAIN_COLOR (state, newColor) {
    state.mainColor = newColor
    state.variables.menuBg = newColor
    setSessionInfo(MAIN_COLOR, newColor)
  }
}

export default {
  namespaced: true,
  state,
  mutations
}
